@/*
    id : id
    modules : 全部组件信息
    value : 值
    isEdit : 是否可编辑
@*/
@if(isEmpty(isEdit)){
@	isEdit="false";
@}
<link type="text/css" href="${ctxPath}/static/libs/layoutbuilder/jquery-ui/jquery-ui.css" rel="stylesheet" media="screen" />
<link type="text/css" href="${ctxPath}/static/libs/layoutbuilder/css/style.css" rel="stylesheet" media="screen" />
<script type="text/javascript" src="${ctxPath}/static/libs/layoutbuilder/js/script.js"></script>
<script type="text/javascript" src="${ctxPath}/static/libs/layoutbuilder/jquery-ui/jquery-ui.js"></script>
<div class="form-horizontal">
    <form method='post' id="workbenchInfoForm" name="workbenchInfoForm" enctype="multipart/form-data">
        <div class="row row-lg">
            <div class="col-sm-12">
                <div id="screenview" >
                    <div class="row">
                        <div class="layout-builder-wrapper col-md-12">
                            <div id="layout-builder" class="layout-builder"></div>
                            <div><textarea name="${id}" class="hidden-content-layout hide" id="${id}">${value}</textarea></div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </form>
</div>
<script>
    var layerIndex = -1;
    //编辑组件
    var openWidgetEdit = function (modId) {
        debugger;
        layerIndex = Sys.open('修改组件',Sys.backendPath + '/oa/workbench/module/to_update/' + modId,['100%', '100%']);
    }

    //浏览所有模块
    function showAllModule(obj,col) {
        this.layerIndex = Sys.open('所有模块',Sys.backendPath + '/oa/workbench/module/all_module',['800px', '405px'],function (layero, index, iframeWin) {
            iframeWin.AllModules.setResponse(obj,col);
        })
    }

    /**
     * 保存操作
     */
    function triggerSaveForm(){
            $(".layout-builder-wrapper").each( function(){
                var output = getLayoutData( $(this).find(".layout-builder") );
                var j = JSON.stringify( output );
                $(".hidden-content-layout",this).html( j );
            } );
            return true;
    }

    function getLayoutData( container ){
        var output = new Array();
        var rowIndex = 1;
        $( container ).children('.inner ').children(".wpo-row").each( function(){
            var _row = $(this);
            var data = _row.data('rowcfg');
            data.index = rowIndex;
            data.cols = new Array();
            var colIndex = 1;
            $(_row).children('.inner').children( '.wpo-col' ).each( function(){
                var _col = $(this).data('colcfg');
                _col.index = colIndex;
                _col.widgets = new Array();
                $(this).children('.inner').children('.wpo-content ').children( '.wpo-ijwidget' ).each( function() {
                    var wd = new Object();
                    wd.name = $(this).data('name');
                    wd.moduleId = $(this).data('moduleid');
                    wd.type = $(this).data('type');
                    _col.widgets.push( wd );
                } );
                _col.rows = new Array();
                if( $(this).children('.inner').children( '.wpo-row' ).length > 0 ){
                    _col.rows = getLayoutData( this );
                }
                data.cols.push( _col );
                colIndex++;
            } );
            output.push( data );
            rowIndex++;
        } );
        return output;
    }
    //删除当前该列
    function delPresentCol(obj) {
        var operation = function(){
            obj();
        }
        Sys.confirm("是否删除该列?",operation);
    }
    //删除改行
    function delPresentRow(obj) {
        var operation = function(){
            obj();
        }
        Sys.confirm("是否删除该行?",operation);
    }

    $(function () {
        var isEdit = ${isEdit}
        var config = {
            isEdit:isEdit
        };
        $( $(".layout-builder", this) ).WPO_Layout(config,$(".hidden-content-layout",this).val() );
    });
</script>
